<template>
	<view class="edit">
		<!-- #ifndef H5 -->
		<topTitle :styles="{back:true,title:'修改昵称',color:'#fff'}" />
		<!-- #endif -->
		<view class="edit_input">
			<input type="text" v-model="option.text" placeholder="请输入修改内容">
			<text v-show="option.text !=''" @click.stop="empty">清空</text>
		</view>
		<view class="submit" @click="submit">
			修改
		</view>
	</view>
</template>

<script>
	import topTitle from "@/components/topTitle.vue"
	export default {
		components:{
			topTitle
		},
		data() {
			return {
				option:"",
			};
		},
		onLoad(option) {
			this.option = option
		},
		methods:{
			//清空输入框
			empty(){
				this.option.text = ""
			},
			//修改
			submit(){
				if(this.option.text == ""){
					uni.showToast({
						title:'请输入修改内容',
						icon:"none"
					})
					return false;
				}
				if(this.option.type == "name"){
					var data = {
						name:this.option.text,
					}
				}else{
					var data = {
						nickname:this.option.text,
					}
				}
				this.$http({
					url:'/api/user/edit',
					method:'post',
					data:data,
					success:result=>{
						console.log(result)
						if(result.code == 200){
							uni.showToast({
								title:result.msg
							})
							setTimeout(()=>{
								uni.navigateBack()
							},1500)
						}
					}
				})
				console.log(data)
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		width: 100%;
		height: 100%;
	}
	.edit{
		width: 100%;
		height: 100%;
		.edit_input{
			width: 100%;
			height: 44px;
			line-height: 40px;
			background-color: #fff;
			position: relative;
			>input{
				width: 100%;
				height: 100%;
				text-indent: 10px;
			}
			>text{
				position: absolute;
				right: 15px;
				top: 0;
				color: #9e9e9e;
			}
		}
		.submit{
			width: 90%;
			height: 44px;
			line-height: 44px;
			background-color: #10C77C;
			color: #fff;
			border-radius: 40px;
			text-align: center;
			margin: 0 auto;
			margin-top: 30px;
		}
	}
</style>
